﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ETL.Business.Models;
using ETL.Common.Logging;
using ETL.DataAccess;
using ETL.Entity;

namespace ETL.Business.Handlers.ProjectNamesHandler
{
    /// <summary>
    /// Get user by id, id with the old system is UserName of the new system
    /// </summary>
    public class GetUserById
    {
        private readonly ProjectResourceInstancesRepository _projectResourceInstancesRepository;

        public GetUserById()
        {
            _projectResourceInstancesRepository = new ProjectResourceInstancesRepository();
        }
        public GetUserById(ProjectResourceInstancesRepository projectResourceInstancesRepository)
        {
            _projectResourceInstancesRepository = projectResourceInstancesRepository;
        }

        public virtual ProjectUserModel Execute(string userId)
        {
            ProjectUserModel projectEngineerModel = null;
            
            try
            {
                // try to get from db
                RESOURCE_INSTANCES prjAllNameItem = 
                    _projectResourceInstancesRepository.GetUserById(userId);

                // parse to business model
                if(prjAllNameItem != null)
                {
                    projectEngineerModel = new ProjectUserModel(prjAllNameItem);
                }

                return projectEngineerModel;
            }
            catch (Exception ex)
            {
                LogService.Service.Debug(ex);
                return null;
            }
        }
    }
}
